const path = require('path')
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
const includePaths = [
    path.resolve(path.join(__dirname, 'src')),
    path.resolve(path.join(__dirname, 'node_modules/vue-codemirror'))
]
module.exports = {
    entry: './src/main.js',
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader: 'vue-loader',
                include: includePaths
            }, {
                test: /\.js?$/,
                loader: 'babel-loader?cacheDirectory=true',
                include: includePaths,
            },
            {
                test: /\.scss$/,
                use: [
                    'vue-style-loader',
                    'css-loader',
                    {
                        loader: "sass-loader",
                        options: {
                            implementation: require("sass"), //使用dart-sass代替node-sass
                        }
                    },
                ]
            },
            {
                test: /\.less$/,
                use: [
                    'vue-style-loader',
                    'css-loader',
                    'less-loader'
                ]
            },
            {
                test: /\.css/,
                use: [
                    'vue-style-loader',
                    'css-loader',
                    'postcss-loader' // 使用postcss-loader
                ]
            },
            {
                test: /\.(png|jpe?g|gif|ttf|svg)$/,
                use: [{
                    loader: 'file-loader?name=assets/[name].[hash:6].[ext]',
                },],
            },
            {
                test: /\.ico$/,
                use: [{
                    loader: 'file-loader',
                },],
            },
            {
                test: /\.(mp3|woff)$/i,
                use: [{
                    loader: 'url-loader',
                }]
            }
        ]
    },
    resolve: {
        extensions: ['.js', '.vue', '.css', '.less', '.json'],
        alias: {
            '@': path.join(__dirname, 'src'),
        },
        modules: [path.resolve(__dirname, "src"), 'node_modules']
    },
    // externals: [
    //     'vue', 'vue-router', 'vuex', 'element-ui','vue-codemirror'
    // ],
    plugins: [
        new VueLoaderPlugin(),
        new HtmlWebpackPlugin({
            title: "后台管理",
            template: path.resolve(__dirname, 'public/index.html'),
            filename: 'index.html',
            favicon: path.resolve(__dirname, "public/favicon.ico"),
            inject: true
        }),
        new CopyWebpackPlugin(
            [
                {
                    from: path.resolve(__dirname, 'src/static'),
                    to: "static",
                    ignore: ['.*']
                },
                {
                    from: path.resolve(__dirname, 'src/assets'),
                    to: "assets"
                }]
        ),
        new webpack.HotModuleReplacementPlugin()
    ]
}